package liuds.music.model;

import com.google.gson.Gson;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/23.
 */

public class RequestParams extends HashMap<String,Object> {
    @Override
    public String toString() {
        return new Gson().toJson(this);
    }

    public String toQueryParam(){
        StringBuilder sb=new StringBuilder();
        boolean isFirst=true;
        for(String key:this.keySet()){
            try{
                String value= URLEncoder.encode(this.get(key)+"","UTF-8");
                if(!isFirst){
                    sb.append("&");
                }
                sb.append(key).append("=").append(value);
                isFirst=false;
            }catch (Exception e){

            }
        }
        return sb.toString();
    }
}
